import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

enum InputType {
  age,
  phone,
  card,
}

class InputOption extends StatelessWidget {
  final TextEditingController controller;
  final String hintText;
  final String label;
  final InputType type;

  InputOption({this.controller, this.hintText, this.label, this.type});

  @override
  Widget build(BuildContext context) {
    var inputFormatters;
    var keyboardType;
    switch (type) {
      case InputType.age:
        inputFormatters = [
          FilteringTextInputFormatter.digitsOnly,
          LengthLimitingTextInputFormatter(3),
        ];
        keyboardType = TextInputType.number;
        break;
      case InputType.phone:
        inputFormatters = [
          FilteringTextInputFormatter.digitsOnly,
          LengthLimitingTextInputFormatter(11),
        ];
        keyboardType = TextInputType.phone;
        break;
      case InputType.card:
        inputFormatters = [
          FilteringTextInputFormatter.digitsOnly,
          LengthLimitingTextInputFormatter(18),
        ];
        keyboardType = TextInputType.phone;
        break;
      default:
        inputFormatters = [
          LengthLimitingTextInputFormatter(20),
        ];
        keyboardType = TextInputType.text;
    }
    return Container(
      height: 60,
      color: Colors.white,
      child: Row(
        children: [
          Container(
            child: Text(label ?? ''),
            constraints: BoxConstraints(minWidth: 120),
            padding: EdgeInsets.only(left: 16),
          ),
          Expanded(
            child: TextField(
              style: TextStyle(fontSize: 15),
              keyboardType: keyboardType,
              autocorrect: false,
              controller: controller,
              maxLines: 1,
              inputFormatters: inputFormatters,
              textInputAction: TextInputAction.next,
              decoration: InputDecoration(
                hintText: hintText,
                hintStyle: TextStyle(color: Colors.grey),
                enabledBorder: UnderlineInputBorder(
                  borderSide: BorderSide(color: Colors.grey[300]),
                ),
                focusedBorder: UnderlineInputBorder(
                  borderSide: BorderSide(color: Colors.grey[300]),
                ),
              ),
            ),
          ),
          SizedBox(width: 16),
        ],
      ),
    );
  }
}

class TextOption extends StatelessWidget {
  final String secondText;
  final String label;
  final GestureTapCallback onTap;
  final Color secondTextColor;
  final bool hideArrow;

  TextOption(
      {this.secondText,
      this.label,
      this.onTap,
      this.secondTextColor,
      this.hideArrow});

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 60,
      color: Colors.white,
      child: Row(
        children: [
          Container(
            child: Text(label ?? ''),
            constraints: BoxConstraints(minWidth: 120),
            padding: EdgeInsets.only(left: 16),
          ),
          Expanded(
            child: InkWell(
              onTap: onTap,
              child: Container(
                height: 50,
                alignment: Alignment.centerLeft,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      secondText ?? '',
                      style: TextStyle(color: secondTextColor ?? Colors.black),
                    ),
                    Offstage(
                      offstage: hideArrow ?? false,
                      child: Image.asset(
                        'assets/images/ic_arrow_right.png',
                        width: 16,
                        height: 16,
                      ),
                    )
                  ],
                ),
                decoration: BoxDecoration(
                    border: Border(
                        bottom: BorderSide(color: Colors.grey[300], width: 1))),
              ),
            ),
          ),
          SizedBox(width: 16),
        ],
      ),
    );
  }
}
